<template>
  <div>
    <div class="card mb-3">
      <div class="card-header bg-white">
        <span class="analy-type-title">报表类型：</span>
        <c-select
          :options="enumAnalyType"
          v-model="analyType"
          @change="handleTypeChange"
        ></c-select>
      </div>
      <div class="card-body">
        <transition name="component-fade" mode="out-in">
          <keep-alive>
            <router-view></router-view>
          </keep-alive>
        </transition>
      </div>
    </div>
  </div>
</template>

<script>
import { enumAnalyType } from '@/credit/views/city/report/analyMixins'

export default {
  components: {},
  props: {},
  data() {
    return {
      enumAnalyType,
      analyType: 0,
    }
  },
  computed: {},
  watch: {},
  created() {
    this.initSelect()
  },
  mounted() {},
  methods: {
    initSelect() {
      const { name } = this.$route
      const routeIndex = enumAnalyType.findIndex(it => it.name === name)
      this.analyType = routeIndex > -1 ? routeIndex : 0
    },
    handleTypeChange(index) {
      this.$router.replace({
        name: enumAnalyType[index].name,
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.component-fade-enter-active,
.component-fade-leave-active {
  transition: opacity 0.2s ease;
}
.component-fade-enter,
.component-fade-leave-to {
  opacity: 0;
}
.analy-type-title {
  font-weight: bold;
  font-size: 1.15rem;
}
</style>
